package com.xjscrm.console.service.customer.sop.impl;

import com.xjscrm.common.constant.ResponseMsg;
import com.xjscrm.common.exception.BusinessException;
import com.xjscrm.common.result.ResponseCode;
import com.xjscrm.console.param.sop.BathchUpdateSopTaskDeviceConfigDto;
import com.xjscrm.console.param.sop.SopTaskDeviceConfigDto;
import com.xjscrm.console.service.customer.sop.SopBatchService;
import com.xjscrm.console.service.customer.sop.SopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class SopBatchServiceImpl implements SopBatchService {

    @Autowired
    private SopService sopService;

    @Override
    public void batchUpdateSopTaskDeviceConfig(BathchUpdateSopTaskDeviceConfigDto bathchUpdateSopTaskDeviceConfigDto) {
        if (bathchUpdateSopTaskDeviceConfigDto.getMerId() == null) {
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, ResponseMsg.MERID_NULL);
        }
        if (bathchUpdateSopTaskDeviceConfigDto.getSopTaskDeviceConfigDtoList() == null || bathchUpdateSopTaskDeviceConfigDto.getSopTaskDeviceConfigDtoList().isEmpty()) {
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, ResponseMsg.PARAMETER_ERROR);
        }

        for (SopTaskDeviceConfigDto sopTaskDeviceConfigDto : bathchUpdateSopTaskDeviceConfigDto.getSopTaskDeviceConfigDtoList()) {
            try {
                sopTaskDeviceConfigDto.setMerId(bathchUpdateSopTaskDeviceConfigDto.getMerId());
                sopService.updateSopTaskDeviceConfig(sopTaskDeviceConfigDto);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
